package com.ruoyi.system.thread;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.concurrent.ThreadPoolExecutor;

public class RejectedExecutionHandler implements java.util.concurrent.RejectedExecutionHandler {
    private static final Logger log = LoggerFactory.getLogger(RejectedExecutionHandler.class);
    @Override
    public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) {
        if (!executor.isShutdown()) {
            try {
                log.info("线程池已满，阻塞，直到将任务放入队列");
                executor.getQueue().put(r);
                log.info("成功将任务放入队列");
            } catch (InterruptedException e) {
                log.error(e.toString(), e);
                Thread.currentThread().interrupt();
            }
        }
    }
}
